home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 171_01 / m8087.mac < prev    next >
Text File  |  1983-11-21  |  29KB  |  818 lines

  1. ;***********************************************************************;
  2. ;                                                                       ;
  3. ;       M8087.MAC - File of macros which provide assembly level         ;
  4. ;                       software support for use of 8087 NDP with       ;
  5. ;                       the IBM personal computer                       ;
  6. ;                                                                       ;
  7. ;       Source: BYTE, August 1983, Vol. 8, No. 8, pp.331-374            ;
  8. ;                                                                       ;
  9. ;       Note - The initial 'if1' and final 'endif' have been removed    ;
  10. ;               from the original BYTE version. My Microsoft 'masm'     ;
  11. ;               balked at the construct hence I dropped it.             ;
  12. ;               Of course the same result is obtained by the statements ;
  13. ;                                                                       ;
  14. ;                       if1                                             ;
  15. ;                               INCLUDE M8087.MAC                       ;
  16. ;                       endif                                           ;
  17. ;                                                                       ;
  18. ;               in your Macro Assembler source, which seems to work.    ;
  19. ;                                                                       ;
  20. ;       The following has not been tested by me, hence use at your own  ;
  21. ;       risk. I hope that this will help stimulate macro development    ;
  22. ;       for Microsoft C in the area of 8087 applications.               ;
  23. ;                                                                       ;
  24. ;***********************************************************************;
  25.  
  26.  
  27.  
  28. ;***********************************************************************;
  29. ;                                                                       ;
  30. ;       ESC_REG - "REG" parameter specifies ESC value.  Issue           ;
  31. ;               proper ESC sequence depending on REQ value.             ;
  32. ;               PARAM is a 6-bit parameter whose upper 3-bits           ;
  33. ;               make up the "xxx" bits in the ESC opcode (11011xxx)     ;
  34. ;               and lower 3-bits make up "yyy" bits in source           ;
  35. ;               byte following (using standard "mod" and "r/m"          ;
  36. ;               designators define byte as "modyyyr/m").                ;
  37. ;                                                                       ;
  38. ;***********************************************************************;
  39.  
  40. ESC_REG macro PARAM,REG
  41.         ;
  42.         ; We need to determine what "reg" field assignment corresponds with
  43.         ; the current value of REG.  This is used as the source for the
  44.         ; ESC operation.  PARAM is used directly in the ESC call
  45.         ;
  46.         ife REG ; Decrement until REG = 0, then issue ESC sequence
  47.           ESC PARAM,AX          ; AX = 000b (see operand summary for 8088)
  48.         else
  49.           REG = REG - 1
  50.           ife REG
  51.             ESC PARAM,CX                ; CX = 001b
  52.           else
  53.             REG = REG - 1
  54.             ife REG
  55.               ESC PARAM,DX              ; DX = 010b
  56.             else
  57.               REG = REG - 1
  58.               ife REG
  59.                 ESC PARAM,BX            ; BX = 011b
  60.               else
  61.                 REG = REG - 1
  62.                 ife REG
  63.                   ESC PARAM,SP          ; SP = 100b
  64.                 else
  65.                   REG = REG - 1
  66.                   ife REG
  67.                     ESC PARAM,BP        ; BP = 101b
  68.                   else
  69.                     REG = REG - 1
  70.                     ife REG
  71.                       ESC PARAM,SI      ; SI = 110b
  72.                     else                ; If REG >= 7, assume 7
  73.                       ESC PARAM,DI      ; DI = 111b
  74.                     endif
  75.                   endif
  76.                 endif
  77.               endif
  78.             endif
  79.           endif
  80.         endif
  81. endm    ; Done with ESC_REG macro
  82.  
  83.  
  84. ;***********************************************************************;
  85. ;                                                                       ;
  86. ;       CHECK_ST - Inputs parameter "ST(i)" and returns with REG=i      ;
  87. ;                                                                       ;
  88. ;***********************************************************************;
  89.  
  90. CHECK_ST macro P_ST
  91.         REG = -1        ; Assume no match is found
  92.         ifidn <&P_ST>,<ST(0)>   ; Is i=0?
  93.           REG = 0
  94.         endif
  95.         ifidn <&P_ST>,<ST(1)>    
  96.           REG = 1
  97.         endif
  98.         ifidn <&P_ST>,<ST(2)>    
  99.           REG = 2
  100.         endif
  101.         ifidn <&P_ST>,<ST(3)>    
  102.           REG = 3
  103.         endif
  104.         ifidn <&P_ST>,<ST(4)>    
  105.           REG = 4
  106.         endif
  107.         ifidn <&P_ST>,<ST(5)>    
  108.           REG = 5
  109.         endif
  110.         ifidn <&P_ST>,<ST(6)>    
  111.           REG = 6
  112.         endif
  113.         ifidn <&P_ST>,<ST(7)>    
  114.           REG = 7
  115.         endif
  116.         ifidn <&P_ST>,<st(0)>   ; Is i=0?        
  117.           REG = 0
  118.         endif
  119.         ifidn <&P_ST>,<st(1)>    
  120.           REG = 1
  121.         endif
  122.         ifidn <&P_ST>,<st(2)>    
  123.           REG = 2
  124.         endif
  125.         ifidn <&P_ST>,<st(3)>    
  126.           REG = 3
  127.         endif
  128.         ifidn <&P_ST>,<st(4)>    
  129.           REG = 4
  130.         endif
  131.         ifidn <&P_ST>,<st(5)>    
  132.           REG = 5
  133.         endif
  134.         ifidn <&P_ST>,<st(6)>    
  135.           REG = 6
  136.         endif
  137.         ifidn <&P_ST>,<st(7)>    
  138.           REG = 7
  139.         endif
  140.         ;
  141.         ; If i not between 0 or 7, see if actually an
  142.         ; "ST(i)" or "ST(I)" string, indicating use of
  143.         ; top of stack element
  144.         ;
  145.         ifidn <&P_ST>,<ST(i)>
  146.           REG = 0
  147.         endif
  148.         ifidn <&P_ST>,<ST(I)>
  149.           REG = 0
  150.         endif
  151.         ifidn <&P_ST>,<st(i)>
  152.           REG = 0
  153.         endif
  154.         ifidn <&P_ST>,<st(I)>
  155.           REG = 0
  156.         endif
  157. endm
  158. ;***********************************************************************;
  159. ;*                                                                      ;
  160. ;*      CHK_CONC - Simple macro that will automatically insert          ;
  161. ;*                      WAIT statements AFTER every 8087 instruction    ;
  162. ;*                      which accesses CPU main memory.  If variable    ;
  163. ;*                      "AUTOSYNC" <> 0, then these WAITs will be       ;
  164. ;*                      inserted (providing no concurrency but relieving;
  165. ;*                      the programmer from worrying about synchronizing;
  166. ;*                      data references. If the user program sets       ;
  167. ;*                      AUTOSYNC to a zero value, then no WAITS         ;
  168. ;*                      are inserted after the instructions and it is   ;
  169. ;*                      the user's responsibility to insure synch-      ;
  170. ;*                      ronization.                                     ;
  171. ;*                                                                      ;
  172. ;***********************************************************************;
  173.  
  174. CHK_CONC macro
  175.  
  176.         if AUTOSYNC
  177.                 WAIT    ; Automatic syncronization
  178.         endif
  179. endm
  180.  
  181.  
  182.  
  183. ;***********************************************************************;
  184. ;                                                                       ;
  185. ;       CHOOSE_4 - Determine which of four parameters (XXX1 to XXX4)    ;
  186. ;                  should be used in ESC sequence, depending on P1      ; 
  187. ;                  and P2 values.  P1 and P@ are parameters passed      ;
  188. ;                  by user in macro call.  XXX1 to XXX4 are macro-      ;
  189. ;                  dependent parameters tacked on to the call to        ;
  190. ;                  CHOOSE_4 by the specific 8087 macro called by the    ;
  191. ;                  user code.                                           ;
  192. ;                                                                       ;
  193. ;***********************************************************************;